//
//  View+Gesture.swift
//  TTCOM
//
//  Created by Toj on 10/20/23.
//

import UIKit

public extension UIView {
    
    func addTarget(_ target: Any?, action: Selector) {
        guard target != nil else { return }
        
        isUserInteractionEnabled = true
        let gesture = UITapGestureRecognizer(target: target, action: action)
        addGestureRecognizer(gesture)
    }
    
    func removeTarget() {
        let gests = self.gestureRecognizers ?? []
        for gest in gests {
            guard gest is UITapGestureRecognizer else { continue }
            removeGestureRecognizer(gest)
            break
        }
    }
}
